package com.hanliukui.ai.langchain4j.assistant.xiaozhi;

import com.hanliukui.ai.langchain4j.assistant.xiaozhi.business.AppointmentPo;
import com.hanliukui.ai.langchain4j.assistant.xiaozhi.business.XiaoziAppointmentService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class XiaoziBusinessTools {

    @Autowired
    private XiaoziAppointmentService xiaoziAppointmentService;

    @Tool(name = "查询预约信息", value = "查询预约信息，根据参数，查询预约信息")
    public List<AppointmentPo> queryAppointment(@P("用户身份证号") String idCard) {
        System.out.println("查询用户预约信息");
        return xiaoziAppointmentService.queryUserAppointments(idCard);
    }

    @Tool(name = "预约挂号", value = "预约挂号，根据参数，你应该先判断有预约号源，并直接给用户回复是否可预约，如果可以预约，让用户确认所有预约信息，用户确认后再进行预约")
    public String bookAppointment(AppointmentPo appointment) {
        System.out.println("预约挂号");
        // 再次检查预约
        AppointmentPo existedAppointment = xiaoziAppointmentService.getAppointment(appointment);
        if (existedAppointment != null) {
            return "您在相同时间已有预约";
        }
        appointment.setId(null);
        xiaoziAppointmentService.createAppointment(appointment);
        return "预约成功";
    }

    @Tool(name = "更新预约信息", value = "更新预约信息，根据参数，更新预约信息，并返回更新结果")
    public String updateAppointment(AppointmentPo appointment) {
        System.out.println("修改预约信息");
        xiaoziAppointmentService.updateAppointment(appointment);
        return "更新成功";
    }

    @Tool(name = "取消预约", value = "取消预约，根据参数，取消预约，并返回取消结果")
    public String cancelAppointment(AppointmentPo appointment) {
        System.out.println("取消预约信息");
        return xiaoziAppointmentService.cancelAppointment(appointment);
    }

    @Tool(name = "检查是否还有预约号", value = "根据预约参数，判断是否还有预约号")
    public String checkAppointment(AppointmentPo appointment) {
        System.out.println("查询是否有号源...");
        System.out.println(appointment);
        // 如果提供了医生名称，查询该医生是否还有预约号，如果没有提供预约号，查询科室是否还有预约号
        return "true";
    }

}
